package cn.wolfcode.wms.qo;

import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Calendar;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

@Getter
@Setter
public class SaleChartQueryObject extends QueryObject {
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date beginTime;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endTime;
    private Long clientId=-1l;
    private Long brandId =-1l;
    private String groupBy="e.name";

    public static final Map<String,String> groupTypes =new LinkedHashMap<>();
    static {
        groupTypes.put("e.name","销售人员");
        groupTypes.put("p.name","货品名称");
        groupTypes.put("c.name","客户");
        groupTypes.put("p.brand_name","品牌");
        groupTypes.put("DATE_FORMAT(sa.vdate,\'%Y-%m\')","销售日期(月)");
        groupTypes.put("DATE_FORMAT(sa.vdate,\'%Y-%m-%d\')","销售日期(日)");
    }
    public void setFinalTime(Date date){
        if (date==null){
            return;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH,1);
        calendar.add(Calendar.SECOND,-1);
        this.beginTime=calendar.getTime();
    }

}
